#Boa:Frame:Frame1

import wx
import wx.lib.dialogs
import re
import os
import sys
import glob
import shutil
import time
import zipfile
import string

from Configure_ver00 import Config
from Data2Bhtc_ver01 import NewUiData2BHTC
from BHTC2CustData_ver00  import BHTC2CustData
from renamefile import Rename
from WaferMapView_ver00 import MyWaferMapFrame

ProjectPath=os.getcwd()
TestDataPath=""
DeviceInData=[]
LotNumInData=""
WaferIdInData="01;"
TestDataDir=""
SortTypesInData="Sort1"
VersionInData={}
DeviceInMapData=[]
VersionInMapData={}
LotNumInMapData=""
SortTypesInMapData=["Sort1"]
DeviceInWaferMap=[]
VersionInWaferMap={}
LotNumInWaferMap=""
WaferIdInWaferMap=""
SortTypesInWaferMap="Sort1"
FlagDevice=False
FlagLotNum=False
#FlagSortType=False
FlagWaferId=False
FlagVersion=False

FlagDeviceInMap=False
FlagLotNumInMap=False
FlagVersionInMap=False

FlagDeviceInWaferMap=False
FlagLotNumInWaferMap=False
FlagVersionInWaferMap=False
FlagWaferIdInWaferMap=False
IndexInWaferMap=0


def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1CONFIGINDATA, wxID_FRAME1CONFIGRATION, 
 wxID_FRAME1CONFIGSTATICBOXINMAPDATA, wxID_FRAME1CONFIGSTATICBOXINWAFERMAP, 
 wxID_FRAME1DEVICECHOICEINDATA, wxID_FRAME1DEVICECHOICEINMAPDATA, 
 wxID_FRAME1DEVICECHOICEINWAFERMAP, wxID_FRAME1DEVICESTATICTEXTINDATA, 
 wxID_FRAME1DEVICESTATICTEXTINMAPDATA, wxID_FRAME1DEVICESTATICTEXTINWAFERMAP, 
 wxID_FRAME1EXITBUTTONINDATA, wxID_FRAME1EXITBUTTONINMAPDATA, 
 wxID_FRAME1EXITBUTTONINWAFERMAP, wxID_FRAME1GAUGEINDATA, 
 wxID_FRAME1LOTNOBUTTONINDATA, wxID_FRAME1LOTNOBUTTONINMAPDATA, 
 wxID_FRAME1LOTNOBUTTONINWAFERMAP, wxID_FRAME1LOTNOSTATICTEXTINMAPDATA, 
 wxID_FRAME1LOTNOTEXTCTRLINDATA, wxID_FRAME1LOTNOTEXTCTRLINMAPDATA, 
 wxID_FRAME1LOTNUMSTATICTEXTINDATA, wxID_FRAME1LOTNUMSTATICTEXTINWAFERMAP, 
 wxID_FRAME1LOTNUMTEXTCTRLINWAFERMAP, wxID_FRAME1MANUALCONVERTTOOL, 
 wxID_FRAME1MAPDATATOOL, wxID_FRAME1NEXTBUTTONINWAFERMAP, 
 wxID_FRAME1NOTEBOOK1, wxID_FRAME1PREBUTTONINWAFERMAP, 
 wxID_FRAME1RECONFIGBUTTONINDATA, wxID_FRAME1SORTTYPERADIOBOXINDATA, 
 wxID_FRAME1SORTTYPERADIOBOXINMAPDATA, wxID_FRAME1SORTTYPERADIOBOXINWAFERMAP, 
 wxID_FRAME1STARTBUTTONINDATA, wxID_FRAME1STARTBUTTONINMAPDATA, 
 wxID_FRAME1STARTBUTTONINWAFERMAP, 
 wxID_FRAME1TESTDATAPATHBUTTONINCONFIGRATION, 
 wxID_FRAME1TESTDATAPATHSTATICTEXTINCONFIGRATION, 
 wxID_FRAME1TESTDATAPATHTEXTCTRLINCOFIGRATION, wxID_FRAME1TITILEINMAPDATA, 
 wxID_FRAME1TITLESTATICTEXTINDATA, wxID_FRAME1TITLESTATICTEXTINWAFERMAP, 
 wxID_FRAME1VERSIONCHOICEINDATA, wxID_FRAME1VERSIONCHOICEINMAPDATA, 
 wxID_FRAME1VERSIONCHOICEINWAFERMAP, wxID_FRAME1VERSIONSTATICTEXTINDATA, 
 wxID_FRAME1VERSIONSTATICTEXTINMAPDATA, 
 wxID_FRAME1VERSIONSTATICTEXTINWAFERMAP, wxID_FRAME1VIEWBUTTONINMAPDATA, 
 wxID_FRAME1WAFERMAPVIEW, wxID_FRAME1WAFERNOSTATICTEXTINDATA, 
 wxID_FRAME1WAFERNOSTATICTEXTINWAFERMAP, wxID_FRAME1WAFERNOTEXTCTRLINDATA, 
 wxID_FRAME1WAFERNOTEXTCTRLINWAFERMAP, 
] = [wx.NewId() for _init_ctrls in range(54)]

class Frame1(wx.Frame):
    def _init_coll_notebook1_Pages(self, parent):
        # generated method, don't edit

        parent.AddPage(imageId=-1, page=self.ManualConvertTool, select=True,
              text=u'ManualConvertTool')
        parent.AddPage(imageId=-1, page=self.WaferMapView, select=False,
              text=u'WaferMapView')
        parent.AddPage(imageId=-1, page=self.MapDataTool, select=False,
              text=u'MapDataTool')
        parent.AddPage(imageId=-1, page=self.Configration, select=False,
              text=u'Configration')

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(457, 221), size=wx.Size(493, 320),
              style=wx.DEFAULT_FRAME_STYLE, title='ManualTool --ByRoger')
        self.SetClientSize(wx.Size(485, 286))

        self.notebook1 = wx.Notebook(id=wxID_FRAME1NOTEBOOK1, name='notebook1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(485, 286), style=0)

        self.Configration = wx.Panel(id=wxID_FRAME1CONFIGRATION,
              name=u'Configration', parent=self.notebook1, pos=wx.Point(0, 0),
              size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.ManualConvertTool = wx.Panel(id=wxID_FRAME1MANUALCONVERTTOOL,
              name=u'ManualConvertTool', parent=self.notebook1, pos=wx.Point(0,
              0), size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.MapDataTool = wx.Panel(id=wxID_FRAME1MAPDATATOOL,
              name=u'MapDataTool', parent=self.notebook1, pos=wx.Point(0, 0),
              size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.TitleStaticTextInData = wx.StaticText(id=wxID_FRAME1TITLESTATICTEXTINDATA,
              label=u'Manual Data Convert Tool', name=u'TitleStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(40, 8),
              size=wx.Size(332, 35), style=0)
        self.TitleStaticTextInData.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.ConfigInData = wx.StaticBox(id=wxID_FRAME1CONFIGINDATA,
              label=u'Config:', name=u'ConfigInData',
              parent=self.ManualConvertTool, pos=wx.Point(8, 56),
              size=wx.Size(360, 152), style=0)
        self.ConfigInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.DeviceStaticTextInData = wx.StaticText(id=wxID_FRAME1DEVICESTATICTEXTINDATA,
              label=u'Device:', name=u'DeviceStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(12, 87),
              size=wx.Size(62, 23), style=0)
        self.DeviceStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.DeviceChoiceInData = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICECHOICEINDATA, name=u'DeviceChoiceInData',
              parent=self.ManualConvertTool, pos=wx.Point(80, 88),
              size=wx.Size(147, 22), style=0)
        self.DeviceChoiceInData.Bind(wx.EVT_CHOICE,
              self.OnDeviceChoiceInDataChoice,
              id=wxID_FRAME1DEVICECHOICEINDATA)

        self.VersionStaticTextInData = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINDATA,
              label=u'Version:', name=u'VersionStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(231, 86),
              size=wx.Size(68, 23), style=0)
        self.VersionStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.VersionChoiceInData = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINDATA, name=u'VersionChoiceInData',
              parent=self.ManualConvertTool, pos=wx.Point(300, 87),
              size=wx.Size(56, 22), style=0)
        self.VersionChoiceInData.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInDataChoice,
              id=wxID_FRAME1VERSIONCHOICEINDATA)

        self.LotNumStaticTextInData = wx.StaticText(id=wxID_FRAME1LOTNUMSTATICTEXTINDATA,
              label=u'Lot No:', name=u'LotNumStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(14, 129),
              size=wx.Size(61, 23), style=0)
        self.LotNumStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNoTextCtrlInData = wx.TextCtrl(id=wxID_FRAME1LOTNOTEXTCTRLINDATA,
              name=u'LotNoTextCtrlInData', parent=self.ManualConvertTool,
              pos=wx.Point(80, 130), size=wx.Size(133, 22), style=0, value=u'')
        self.LotNoTextCtrlInData.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoTextCtrlInData.Bind(wx.EVT_TEXT,
              self.OnLotNoTextCtrlInDataText,
              id=wxID_FRAME1LOTNOTEXTCTRLINDATA)

        self.LotNoButtonInData = wx.Button(id=wxID_FRAME1LOTNOBUTTONINDATA,
              label=u'...', name=u'LotNoButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(210, 129),
              size=wx.Size(19, 24), style=0)
        self.LotNoButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInData.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInDataButton, id=wxID_FRAME1LOTNOBUTTONINDATA)

        self.WaferNoStaticTextInData = wx.StaticText(id=wxID_FRAME1WAFERNOSTATICTEXTINDATA,
              label=u'WaferNo:', name=u'WaferNoStaticTextInData',
              parent=self.ManualConvertTool, pos=wx.Point(15, 172),
              size=wx.Size(80, 23), style=0)
        self.WaferNoStaticTextInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.WaferNoTextCtrlInData = wx.TextCtrl(id=wxID_FRAME1WAFERNOTEXTCTRLINDATA,
              name=u'WaferNoTextCtrlInData', parent=self.ManualConvertTool,
              pos=wx.Point(100, 173), size=wx.Size(260, 22), style=0,
              value=u'01;')
        self.WaferNoTextCtrlInData.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.WaferNoTextCtrlInData.Bind(wx.EVT_TEXT,
              self.OnWaferNoTextCtrlInDataText,
              id=wxID_FRAME1WAFERNOTEXTCTRLINDATA)

        self.GaugeInData = wx.Gauge(id=wxID_FRAME1GAUGEINDATA,
              name=u'GaugeInData', parent=self.ManualConvertTool,
              pos=wx.Point(9, 220), range=100, size=wx.Size(358, 19),
              style=wx.GA_HORIZONTAL)

        self.StartButtonInData = wx.Button(id=wxID_FRAME1STARTBUTTONINDATA,
              label=u'Start', name=u'StartButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(376, 80),
              size=wx.Size(80, 32), style=0)
        self.StartButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInData.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInDataButton, id=wxID_FRAME1STARTBUTTONINDATA)

        self.ReConfigButtonInData = wx.Button(id=wxID_FRAME1RECONFIGBUTTONINDATA,
              label=u'ReConfig', name=u'ReConfigButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(376, 144),
              size=wx.Size(80, 32), style=0)
        self.ReConfigButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ReConfigButtonInData.Bind(wx.EVT_BUTTON,
              self.OnReConfigButtonInDataButton,
              id=wxID_FRAME1RECONFIGBUTTONINDATA)

        self.ExitButtonInData = wx.Button(id=wxID_FRAME1EXITBUTTONINDATA,
              label=u'Exit', name=u'ExitButtonInData',
              parent=self.ManualConvertTool, pos=wx.Point(376, 208),
              size=wx.Size(80, 32), style=0)
        self.ExitButtonInData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInData.Bind(wx.EVT_BUTTON, self.OnExitButtonInDataButton,
              id=wxID_FRAME1EXITBUTTONINDATA)

        self.TestDataPathStaticTextInConfigration = wx.StaticText(id=wxID_FRAME1TESTDATAPATHSTATICTEXTINCONFIGRATION,
              label=u'TestDataPath:',
              name=u'TestDataPathStaticTextInConfigration',
              parent=self.Configration, pos=wx.Point(11, 24), size=wx.Size(118,
              23), style=0)
        self.TestDataPathStaticTextInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.TestDataPathTextCtrlInCofigration = wx.TextCtrl(id=wxID_FRAME1TESTDATAPATHTEXTCTRLINCOFIGRATION,
              name=u'TestDataPathTextCtrlInCofigration',
              parent=self.Configration, pos=wx.Point(133, 26), size=wx.Size(243,
              22), style=0, value=u'')
        self.TestDataPathTextCtrlInCofigration.Bind(wx.EVT_TEXT,
              self.OnTestDataPathTextCtrlInCofigrationText,
              id=wxID_FRAME1TESTDATAPATHTEXTCTRLINCOFIGRATION)

        self.TestDataPathButtonInConfigration = wx.Button(id=wxID_FRAME1TESTDATAPATHBUTTONINCONFIGRATION,
              label=u'...', name=u'TestDataPathButtonInConfigration',
              parent=self.Configration, pos=wx.Point(374, 25), size=wx.Size(40,
              24), style=0)
        self.TestDataPathButtonInConfigration.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))
        self.TestDataPathButtonInConfigration.Bind(wx.EVT_BUTTON,
              self.OnTestDataPathButtonInConfigrationButton,
              id=wxID_FRAME1TESTDATAPATHBUTTONINCONFIGRATION)

        self.SortTypeRadioBoxInData = wx.RadioBox(choices=['Sort1', 'Sort2'],
              id=wxID_FRAME1SORTTYPERADIOBOXINDATA, label=u'SortType:',
              majorDimension=2, name=u'SortTypeRadioBoxInData',
              parent=self.ManualConvertTool, point=wx.Point(234, 113),
              size=wx.Size(122, 55), style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInData.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.BOLD, False, u'Tahoma'))
        self.SortTypeRadioBoxInData.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInDataRadiobox,
              id=wxID_FRAME1SORTTYPERADIOBOXINDATA)

        self.TitileInMapData = wx.StaticText(id=wxID_FRAME1TITILEINMAPDATA,
              label=u'MapData Convert Tool ', name=u'TitileInMapData',
              parent=self.MapDataTool, pos=wx.Point(60, 8), size=wx.Size(294,
              35), style=0)
        self.TitileInMapData.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.ConfigStaticBoxInMapData = wx.StaticBox(id=wxID_FRAME1CONFIGSTATICBOXINMAPDATA,
              label=u'Config', name=u'ConfigStaticBoxInMapData',
              parent=self.MapDataTool, pos=wx.Point(8, 48), size=wx.Size(352,
              208), style=0)

        self.DeviceStaticTextInMapData = wx.StaticText(id=wxID_FRAME1DEVICESTATICTEXTINMAPDATA,
              label=u'Device:', name=u'DeviceStaticTextInMapData',
              parent=self.MapDataTool, pos=wx.Point(18, 76), size=wx.Size(62,
              23), style=0)
        self.DeviceStaticTextInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.VersionStaticTextInMapData = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINMAPDATA,
              label=u'Version:', name=u'VersionStaticTextInMapData',
              parent=self.MapDataTool, pos=wx.Point(203, 78), size=wx.Size(68,
              23), style=0)
        self.VersionStaticTextInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNoStaticTextInMapData = wx.StaticText(id=wxID_FRAME1LOTNOSTATICTEXTINMAPDATA,
              label=u'LotNo:', name=u'LotNoStaticTextInMapData',
              parent=self.MapDataTool, pos=wx.Point(20, 128), size=wx.Size(55,
              23), style=0)
        self.LotNoStaticTextInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNoTextCtrlInMapData = wx.TextCtrl(id=wxID_FRAME1LOTNOTEXTCTRLINMAPDATA,
              name=u'LotNoTextCtrlInMapData', parent=self.MapDataTool,
              pos=wx.Point(84, 131), size=wx.Size(180, 22), style=0, value=u'')
        self.LotNoTextCtrlInMapData.Bind(wx.EVT_TEXT,
              self.OnLotNoTextCtrlInMapDataText,
              id=wxID_FRAME1LOTNOTEXTCTRLINMAPDATA)

        self.LotNoButtonInMapData = wx.Button(id=wxID_FRAME1LOTNOBUTTONINMAPDATA,
              label=u'Open', name=u'LotNoButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(264, 129), size=wx.Size(88,
              26), style=0)
        self.LotNoButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInMapDataButton,
              id=wxID_FRAME1LOTNOBUTTONINMAPDATA)

        self.SortTypeRadioBoxInMapData = wx.RadioBox(choices=['Sort1', 'Sort2',
              'All Type'], id=wxID_FRAME1SORTTYPERADIOBOXINMAPDATA,
              label=u'SortType:', majorDimension=3,
              name=u'SortTypeRadioBoxInMapData', parent=self.MapDataTool,
              point=wx.Point(22, 176), size=wx.Size(328, 64),
              style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.SortTypeRadioBoxInMapData.SetExtraStyle(1)
        self.SortTypeRadioBoxInMapData.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInMapDataRadiobox,
              id=wxID_FRAME1SORTTYPERADIOBOXINMAPDATA)

        self.StartButtonInMapData = wx.Button(id=wxID_FRAME1STARTBUTTONINMAPDATA,
              label=u'Start', name=u'StartButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(384, 80), size=wx.Size(75,
              24), style=0)
        self.StartButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInMapDataButton,
              id=wxID_FRAME1STARTBUTTONINMAPDATA)

        self.ViewButtonInMapData = wx.Button(id=wxID_FRAME1VIEWBUTTONINMAPDATA,
              label=u'View', name=u'ViewButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(384, 144), size=wx.Size(75,
              24), style=0)
        self.ViewButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ViewButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnViewButtonInMapDataButton,
              id=wxID_FRAME1VIEWBUTTONINMAPDATA)

        self.ExitButtonInMapData = wx.Button(id=wxID_FRAME1EXITBUTTONINMAPDATA,
              label=u'Exit', name=u'ExitButtonInMapData',
              parent=self.MapDataTool, pos=wx.Point(384, 208), size=wx.Size(75,
              24), style=0)
        self.ExitButtonInMapData.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInMapData.Bind(wx.EVT_BUTTON,
              self.OnExitButtonInMapDataButton,
              id=wxID_FRAME1EXITBUTTONINMAPDATA)

        self.DeviceChoiceInMapData = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICECHOICEINMAPDATA,
              name=u'DeviceChoiceInMapData', parent=self.MapDataTool,
              pos=wx.Point(88, 80), size=wx.Size(112, 22), style=0)
        self.DeviceChoiceInMapData.Bind(wx.EVT_CHOICE,
              self.OnDeviceChoiceInMapDataChoice,
              id=wxID_FRAME1DEVICECHOICEINMAPDATA)

        self.VersionChoiceInMapData = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINMAPDATA,
              name=u'VersionChoiceInMapData', parent=self.MapDataTool,
              pos=wx.Point(269, 81), size=wx.Size(80, 22), style=0)
        self.VersionChoiceInMapData.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInMapDataChoice,
              id=wxID_FRAME1VERSIONCHOICEINMAPDATA)

        self.WaferMapView = wx.Panel(id=wxID_FRAME1WAFERMAPVIEW,
              name=u'WaferMapView', parent=self.notebook1, pos=wx.Point(0, 0),
              size=wx.Size(477, 259), style=wx.TAB_TRAVERSAL)

        self.TitleStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1TITLESTATICTEXTINWAFERMAP,
              label=u'WaferMap View Tool', name=u'TitleStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(80, 24), size=wx.Size(263,
              35), style=0)
        self.TitleStaticTextInWaferMap.SetFont(wx.Font(22, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.ConfigStaticBoxInWaferMap = wx.StaticBox(id=wxID_FRAME1CONFIGSTATICBOXINWAFERMAP,
              label=u'Config', name=u'ConfigStaticBoxInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(8, 72), size=wx.Size(368,
              176), style=0)
        self.ConfigStaticBoxInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.DeviceStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1DEVICESTATICTEXTINWAFERMAP,
              label=u'Device:', name=u'DeviceStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(16, 101), size=wx.Size(62,
              23), style=0)
        self.DeviceStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.DeviceChoiceInWaferMap = wx.Choice(choices=[],
              id=wxID_FRAME1DEVICECHOICEINWAFERMAP,
              name=u'DeviceChoiceInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(80, 104), size=wx.Size(140, 22), style=0)
        self.DeviceChoiceInWaferMap.Bind(wx.EVT_CHOICE,
              self.OnDeviceChoiceInWaferMapChoice,
              id=wxID_FRAME1DEVICECHOICEINWAFERMAP)

        self.VersionStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1VERSIONSTATICTEXTINWAFERMAP,
              label=u'Version:', name=u'VersionStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(225, 104), size=wx.Size(68,
              23), style=0)
        self.VersionStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.VersionChoiceInWaferMap = wx.Choice(choices=[],
              id=wxID_FRAME1VERSIONCHOICEINWAFERMAP,
              name=u'VersionChoiceInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(296, 104), size=wx.Size(73, 22), style=0)
        self.VersionChoiceInWaferMap.Bind(wx.EVT_CHOICE,
              self.OnVersionChoiceInWaferMapChoice,
              id=wxID_FRAME1VERSIONCHOICEINWAFERMAP)

        self.LotNumStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1LOTNUMSTATICTEXTINWAFERMAP,
              label=u'Lot No:', name=u'LotNumStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(16, 151), size=wx.Size(61,
              23), style=0)
        self.LotNumStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))

        self.LotNumTextCtrlInWaferMap = wx.TextCtrl(id=wxID_FRAME1LOTNUMTEXTCTRLINWAFERMAP,
              name=u'LotNumTextCtrlInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(80, 154), size=wx.Size(120, 22), style=0, value=u'')
        self.LotNumTextCtrlInWaferMap.Bind(wx.EVT_TEXT,
              self.OnLotNumTextCtrlInWaferMapText,
              id=wxID_FRAME1LOTNUMTEXTCTRLINWAFERMAP)

        self.SortTypeRadioBoxInWaferMap = wx.RadioBox(choices=['Sort1',
              'Sort2'], id=wxID_FRAME1SORTTYPERADIOBOXINWAFERMAP,
              label=u'SortType', majorDimension=2,
              name=u'SortTypeRadioBoxInWaferMap', parent=self.WaferMapView,
              point=wx.Point(232, 136), size=(135, 49),
              style=wx.RA_SPECIFY_COLS)
        self.SortTypeRadioBoxInWaferMap.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL,
              wx.BOLD, False, u'Tahoma'))
        self.SortTypeRadioBoxInWaferMap.Bind(wx.EVT_RADIOBOX,
              self.OnSortTypeRadioBoxInWaferMapRadiobox,
              id=wxID_FRAME1SORTTYPERADIOBOXINWAFERMAP)

        self.LotNoButtonInWaferMap = wx.Button(id=wxID_FRAME1LOTNOBUTTONINWAFERMAP,
              label=u'...', name=u'LotNoButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(198, 153), size=wx.Size(24,
              24), style=0)
        self.LotNoButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.LotNoButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnLotNoButtonInWaferMapButton,
              id=wxID_FRAME1LOTNOBUTTONINWAFERMAP)

        self.WaferNoStaticTextInWaferMap = wx.StaticText(id=wxID_FRAME1WAFERNOSTATICTEXTINWAFERMAP,
              label=u'WaferNo:', name=u'WaferNoStaticTextInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(18, 200), size=wx.Size(80,
              23), style=0)
        self.WaferNoStaticTextInWaferMap.SetFont(wx.Font(14, wx.SWISS,
              wx.NORMAL, wx.NORMAL, False, u'Tahoma'))

        self.WaferNoTextCtrlInWaferMap = wx.TextCtrl(id=wxID_FRAME1WAFERNOTEXTCTRLINWAFERMAP,
              name=u'WaferNoTextCtrlInWaferMap', parent=self.WaferMapView,
              pos=wx.Point(102, 203), size=wx.Size(266, 22), style=0,
              value=u'01;')
        self.WaferNoTextCtrlInWaferMap.Bind(wx.EVT_TEXT,
              self.OnWaferNoTextCtrlInWaferMapText,
              id=wxID_FRAME1WAFERNOTEXTCTRLINWAFERMAP)

        self.StartButtonInWaferMap = wx.Button(id=wxID_FRAME1STARTBUTTONINWAFERMAP,
              label=u'View', name=u'StartButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 82), size=wx.Size(75,
              32), style=0)
        self.StartButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.StartButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnStartButtonInWaferMapButton,
              id=wxID_FRAME1STARTBUTTONINWAFERMAP)

        self.NextButtonInWaferMap = wx.Button(id=wxID_FRAME1NEXTBUTTONINWAFERMAP,
              label=u'Next', name=u'NextButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 128), size=wx.Size(75,
              32), style=0)
        self.NextButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.NextButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnNextButtonInWaferMapButton,
              id=wxID_FRAME1NEXTBUTTONINWAFERMAP)

        self.PreButtonInWaferMap = wx.Button(id=wxID_FRAME1PREBUTTONINWAFERMAP,
              label=u' Prev', name=u'PreButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 173), size=wx.Size(75,
              32), style=0)
        self.PreButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.PreButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnPreButtonInWaferMapButton,
              id=wxID_FRAME1PREBUTTONINWAFERMAP)

        self.ExitButtonInWaferMap = wx.Button(id=wxID_FRAME1EXITBUTTONINWAFERMAP,
              label=u'Exit', name=u'ExitButtonInWaferMap',
              parent=self.WaferMapView, pos=wx.Point(392, 216), size=wx.Size(75,
              32), style=0)
        self.ExitButtonInWaferMap.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL,
              wx.NORMAL, False, u'Tahoma'))
        self.ExitButtonInWaferMap.Bind(wx.EVT_BUTTON,
              self.OnExitButtonInWaferMapButton,
              id=wxID_FRAME1EXITBUTTONINWAFERMAP)

        self._init_coll_notebook1_Pages(self.notebook1)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.MyInit()
    def MyInit(self):
        global TestDataPath
        global DeviceInData
        global VersionInData
        
        self.StartButtonInData.Disable()
        self.ReConfigButtonInData.Disable()
        self.StartButtonInMapData.Disable()
        self.ViewButtonInMapData.Disable()
        self.StartButtonInWaferMap.Disable()
        self.NextButtonInWaferMap.Disable()
        self.PreButtonInWaferMap.Disable()
        self.DeviceChoiceInData.Clear()
        self.DeviceChoiceInMapData.Clear()
        self.DeviceChoiceInWaferMap.Clear()
        DeviceInData=[]
        
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)
        
        InitiFile=open("InitSetting_Manual","r")
        for Line in InitiFile.readlines():
            if re.search(r'TestDataDir=',Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=',Line)
                TestDataDir=TempArray[1] 
                self.TestDataPathTextCtrlInCofigration.SetValue(TestDataDir)
            elif re.search(r'Device=',Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                self.DeviceChoiceInData.Append(TempArray[1])
                self.DeviceChoiceInMapData.Append(TempArray[1])
                self.DeviceChoiceInWaferMap.Append(TempArray[1])
        InitiFile.close
        
    def OnDeviceChoiceInDataChoice(self, event):
        
        global DeviceInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        DeviceInData=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)
        
        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInData.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInData,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInData.Append(TempArray[Index])
                    
        #    elif re.search(r'Device=',Line,re.I):
        #        Line=Line.strip()
        #        TempArray=re.split(r'=|,',Line)
        #        DeviceInData.append(TempArray[1])
        #        VersionInData[TempArray[1]]=TempArray[3]
        #self.DeviceChoiceInData.SetValue(DeviceInData)        
        InitiFile.close      
        if DeviceInData=="":
            FlagDevice=False
        else:
            FlagDevice=True
        
        if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
        else:
            self.StartButtonInData.Disable()
            
        #print DeviceInData,"FlagDevice:",FlagDevice

    def OnVersionChoiceInDataChoice(self, event):
        global VersionInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        VersionInData=event.GetString()
        if VersionInData=="":
            FlagVersion=False
        else:
            FlagVersion=True
        
        if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
        else:
            self.StartButtonInData.Disable()    
        #print VersionInData,"FlagVersion:",FlagVersion

    def OnLotNoTextCtrlInDataText(self, event):
        global LotNumInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        LotNumInData =event.GetString()
        if LotNumInData=="":
           FlagLotNum=False
        else:
           FlagLotNum=True
        
        if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
        else:
            self.StartButtonInData.Disable()   
        #print LotNumInData,"FlagLotNum:",FlagLotNum

    def OnWaferNoTextCtrlInDataText(self, event):    
        global WaferIDInData
        global FlagDevice
        global FlagLotNum
        #global FlagSortType
        global FlagWaferId
        global FlagVersion
        
        WaferIDInData=""
        TempData=event.GetString()
        if TempData == "":
            dlg = wx.MessageDialog(self, 'The WaferID must not be empty In MapData!\n The format is 01;02;...',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
			
        TempArray=re.split(r";",TempData)
        TempFlag=0
        for Temp in TempArray:
            if re.search("\D+",Temp,re.I):
                TempFlag=1
                continue
            elif len(Temp)>0:
				if int(Temp)>25:
					TempFlag=2
            else:
                TempArray.remove(Temp)        
				
		if TempFlag==1:
			dlg = wx.MessageDialog(self, 'There is some no digital in WaferID string In Data! ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
			dlg.ShowModal()
			dlg.Destroy()
		elif TempFlag==2:
			dlg = wx.MessageDialog(self, 'There is some wrong waferID(That is more than 25 In Data!',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
			dlg.ShowModal()
			dlg.Destroy() 
			
		WaferIDInData=TempArray
		if len(WaferIDInData)<1:
                    FlagWaferId=False
                else:
                    FlagWaferId=True
                if FlagDevice and FlagVersion and FlagLotNum  and FlagWaferId:
                    self.StartButtonInData.Enable()
                    self.ReConfigButtonInData.Enable()
                    self.ExitButtonInData.Enable()
                else:
                    self.StartButtonInData.Disable()
                    
                #print WaferIDInData,"FlagWaferId:",FlagWaferId

    def OnStartButtonInDataButton(self, event):
        
        self.StartButtonInData.Disable()
        self.ReConfigButtonInData.Disable()
        self.ExitButtonInData.Disable()
        global DeviceInData 
        global SortTypesInData
        global LotNumInData
        global WaferIDInData
        global TestDataDir
        global VersionInData
        global TestDataDir
	
        #Device=DeviceInData	
        if DeviceInData=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        if WaferIDInData=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The WaferId must not be empty In Data!\n Maybe the format is not right!the right format is 01;02;... ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        elif LotNumInData=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        try:
            os.chdir(TestDataDir)
	
        except OSError:
            msg="".join((r"The TestDataPath:\"",TestDataDir,"\"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        DeviceVersion="".join((DeviceInData,"_",VersionInData))    
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInData)
        try:
            os.chdir(LotPath)
	
        except OSError:
            msg="".join((r"The Lot directory:",LotPath,"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        else:
            self.RunDataProcess(DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData)
            #ProcessShowThread=self.MyThread(self.ProcessShow(len(WaferIDInData)))
            #self.GaugeInData.SetValue(1)
            #RunDataProcessThread=self.MyThread(self.RunDataProcess(DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData))
            #ProcessShowThread.start()
            #RunDataProcessThread.start()
            #self.ProcessShow(len(WaferIDInData))  
            #CurrentPath=os.getcwd()
            #self.RunDataProcess(DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData)
        self.ReConfigButtonInData.Enable()
        self.ExitButtonInData.Enable()    
    def RunDataProcess(self,DeviceInData,SortTypesInData,LotNumInData,WaferIDInData,TestDataDir,VersionInData):            
            Device=DeviceInData	
            ConfigPath=os.path.join(ProjectPath,"Config")
            LogPath=os.path.join(ProjectPath,"Log")
            BinDefinePath=os.path.join(ProjectPath,"Parameter")
            TempPath=os.path.join(ProjectPath,"Tmp")
            if not os.path.isdir(TempPath):
                os.mkdir(TempPath)
            ##############################################
            #Initial file directory!
            #############################################

            TempFileBHTC=os.path.join(TempPath,"bhtc_manual")
            TempOrgFileBHTC=os.path.join(TempPath,"orgbhtc")
            ErrorLogFile=os.path.join(LogPath,"error.log")
            ConfigureFile=os.path.join(ConfigPath,"config_NewUi")
	      
            ##################################################
            #Start enter lot that need to manual convert lot
            ##################################################
            DeviceVersion="".join((Device,"_",VersionInData))
            LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInData)
            DataPath=os.path.join(LotPath,"Data") 
            RetestDataPath=os.path.join(LotPath,"Retest")        
            TimeConvert=time.asctime()
            #self.GaugeInData.SetValue(2)
            GaugeCount=0
            
            for WaferId in WaferIDInData:
                for SortType in [SortTypesInData]:                    
                    WaferFile=""
                    ##################################################
                    #Start new wafer that don't converted!
                    ##################################################
                    if re.search("_",LotNumInData,re.I):
                        TempArrayDatas=re.split("_",LotNumInData,re.I)
                        LotWaferId="".join((TempArrayDatas[0],"-",str(WaferId)))
                    else:
                        LotWaferId="".join((LotNumInData,"-",str(WaferId)))
                    Version=""
                    Patch=""
                    TesterName=""
                    OperatorName=""
                    ChannelMap=""
                    Title=""
                    StarTime=""
                    TestItemNum=""
                    DigitalTestItemNum=""
                    TestItemName=""
                    FileBHTC=""
                    RetestDataFiles=[]
                    FlagRetest=False
                    FlagRetestDataFileExist=False
                    FlagExisitBHTC=False
                    FlagExisitWaferFile=False
                    FlagTest="data"
                    FlagConfig=False
                    #FlagData=False
                    FlagRun=0
                    TimeConvert=time.asctime()
                    #print TimeConvert
                    TempLotWaferId=re.split("-",LotWaferId)
                    LotNum=TempLotWaferId[0]
                    WaferId=int(TempLotWaferId[1])
                    if len(TempLotWaferId[1])<2:
                        LotWaferId="".join((TempLotWaferId[0],"-","0",TempLotWaferId[1]))
				
                    ######################################################
                    #Got all configure parameter from configure file
                    ######################################################
                    (FlagConfig,Version,Patch,TestItemNum,DigitalTestItemNum,TestItemNames)=Config(Device,SortType,ConfigPath,ConfigureFile)
		    
                    ##############################################################
                    #Find WaferFile In Data directory only for Manual Converting 
                    
                    try:
                        os.chdir(DataPath)
                    except OSError:
                        msg="".join((r"The TestDataPath:\"",DataPath,"\"isn't exist!When Using Manual Convert Data Tool."))
                        dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
                        dlg.ShowModal()
                        dlg.Destroy()
                    
                    else:    
                        ###############################################
                        #For Old UI because the file format is txt
                        ###############################################
                        os.chdir(DataPath)
                        if len(glob.glob("*.txt")):
                            Rename(DataPath,"txt","data")
                        TempFiles=glob.glob("*.data")
                        for TempFile in TempFiles:
                            TempArrayDatas=re.split("_",TempFile)
                            Temp=re.split("-",TempArrayDatas[4])
                            if (re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3])) :
                                WaferFile=TempFile
                                FlagExisitWaferFile=True
                                break		
                        if not FlagExisitWaferFile:
                            ZipFileName="".join((Device,"_",VersionInData,"_",os.path.basename(LotPath),"_",SortType,"_",FlagTest,".zip"))
                            if os.path.isfile(ZipFileName):
                                FileName=zipfile.ZipFile(ZipFileName,"r")
                                for TempFile in FileName.namelist():
                                    TempArrayDatas=re.split("_",TempFile)
                                    Temp=re.split("-",TempArrayDatas[4])
                                    if (re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3])) :                   
                                        WaferFile=TempFile
                                        WaferFileFH=open(WaferFile,"w")
                                        WaferFileFH.write(FileName.read(WaferFile))
                                        WaferFileFH.close()
                                        FlagExisitWaferFile=True
                                        break
                                FileName.close()
                                
                                    
                        if FlagExisitWaferFile:                       
                            if FlagConfig:
                                GaugeCount=GaugeCount+float(3)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)
                                ##################################
                                #Delete Temp bhtc File if exists
                                ##################################
                                if os.path.isfile(TempFileBHTC):
                                    os.unlink(TempFileBHTC)
                                if os.path.isdir(RetestDataPath):
              			    os.chdir(RetestDataPath)
              			    ZipFileName="".join((Device,"_",VersionInData,"_",os.path.basename(LotPath),"_",SortType,"_","Retest",".zip"))
                                    if os.path.isfile(ZipFileName):
                                        FileName=zipfile.ZipFile(ZipFileName,"r")
                                        for TempFile in FileName.namelist():
                                            TempArrayDatas=re.split("_",TempFile)
                                            Temp=re.split("-",TempArrayDatas[4])
                                            if string.upper(SortType)==string.upper("Sort1"):
                                                if (re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3])) :                   
                                                    RetestDataFile=TempFile
                                                    RetestDataFileFH=open(RetestDataFile,"w")
                                                    RetestDataFileFH.write(FileName.read(RetestDataFile))
                                                    RetestDataFileFH.close()                                                   
                                                    
                                            else:
                                                if(re.search(LotNum,TempFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper("Sort0")== string.upper(TempArrayDatas[3]) or string.upper(SortType) == string.upper(TempArrayDatas[3])) :                   
                                                    RetestDataFile=TempFile
                                                    RetestDataFileFH=open(RetestDataFile,"w")
                                                    RetestDataFileFH.write(FileName.read(RetestDataFile))
                                                    RetestDataFileFH.close()
                                                    
                                                    
                                        FileName.close()
                                    
                                    GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    
                                    ###############################################
              			    #For Old UI because the file format is txt
              			    ###############################################
              			    if len(glob.glob("*.txt")):
              			      Rename(RetestDataPath,"txt","data")
              			    TempRetestDataFiles=glob.glob("*.data")
              			    TempFiles=glob.glob("*.data")
              			    Date=[]
              			    Time=[]
              			    RetestDataFileNum=0
              			    ###################################################
              			    #Find the all retest file of the related wafer
              			    #and sort the retest files by tested time
              			    ###################################################
              			    
              			    for TempRetestDataFile in TempFiles:
                                        TempArrayDatas=re.split("_",TempRetestDataFile)
                                        Temp=re.split("-",TempArrayDatas[4])
                                        ReSortType="Sort0"                  
                                        if (re.search(LotNum,TempRetestDataFile,re.I))and (WaferId ==int(Temp[1]))and (string.upper(SortType) == string.upper(TempArrayDatas[3]) or string.upper(ReSortType)==string.upper(TempArrayDatas[3])) :
                                          TempDatas=re.split(r"_|\.",TempRetestDataFile)
                                          Date.append(TempDatas[5])
                                          Time.append(TempDatas[6])
                                          RetestDataFileNum=RetestDataFileNum+1
                                          FlagRetest=True
                                        else:
                                          TempRetestDataFiles.remove(TempRetestDataFile)
              			    TempDate=""
              			    TempTime=""
              			    GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
              			    for Index1 in range(RetestDataFileNum):
                                        for Index2 in range(RetestDataFileNum):                            
                                          if int(Date[Index1])<int(Date[Index2]):
                                            TempDate=Date[Index2]
                                            TempTime=Time[Index2]
                                            Date[Index2]=Date[Index1]
                                            Time[Index2]=Time[Index1]
                                            Date[Index1]=TempDate
                                            Time[Index1]=TempTime
                                          elif int(Date[Index1])<int(Date[Index2]):  
                                            if int(Time[Index1])<int(Time[Index2]):
                                              TempDate=Date[Index2]
                                              TempTime=Time[Index2]
                                              Date[Index2]=Date[Index1]
                                              Time[Index2]=Time[Index1]
                                              Date[Index1]=TempDate
                                              Time[Index1]=TempTime
              			    #RetestDataFiles=[] 
              			    
                                    GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    
                                    for Index in range(RetestDataFileNum):                
                                        for TempFile in TempRetestDataFiles:                  
                                            if re.search(Date[Index],TempFile,re.I) and re.search(Time[Index],TempFile,re.I):
                                                RetestDataFiles.append(TempFile)
                                                TempRetestDataFiles.remove(TempFile)
              			GaugeCount=GaugeCount+float(1)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)    
              			######################################################
              			#Find if there is BHTC file when retest data exist
              			######################################################
              			BHTCPath=os.path.join(LotPath,"bhtc")
              			    
              			if os.path.isdir(BHTCPath):
              			    os.chdir(BHTCPath)
              			    TempBHTCFiles=glob.glob("*.bhtc")
              			    for TempFile in TempBHTCFiles:
                                        TempArrayDatas=re.split("_|\.",TempFile)                  
                                        if re.search(LotNum,TempFile,re.I)and (WaferId==int(TempArrayDatas[-2])):
                                            shutil.copyfile(TempFile,TempFileBHTC)                      
                                            FileBHTC=os.path.join(BHTCPath,TempFile)
                                            FlagExisitBHTC=True
                                            break
              			
                                GaugeCount=GaugeCount+float(2)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)
                                #########################################
              			#Covert data
              			#########################################
              			if FlagExisitBHTC and FlagRetest:
              			    shutil.move(FileBHTC,TempOrgFileBHTC)
              			else:
              			    if os.path.isfile(FileBHTC):
                                        os.unlink(FileBHTC)
              			    (FlagRun,StarTime,ProgramName,TesterName,Operator,ChannelMap)=NewUiData2BHTC(LotPath,WaferFile,TempFileBHTC,TestItemNum,TestItemNames,DigitalTestItemNum,FlagTest)  
              			    ###############################################
              			    #Zip the converted data file 
              			    ###############################################
              			    GaugeCount=GaugeCount+float(25)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    if not FlagRun:
                                        os.chdir(os.path.join(LotPath,FlagTest))
                                        if re.search("Sort1",SortType,re.I):
                                            ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_",SortType,"_",FlagTest,".zip"))
                                            self.MyZipFile(ZipFileName,WaferFile,True)
                                        if re.search("Sort2",SortType,re.I) or re.search("Sort0",SortType,re.I):
                                            ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_","Sort2","_",FlagTest,".zip"))
                                            self.MyZipFile(ZipFileName,WaferFile,True)
              			        
              			if FlagRetest:
              			    TempFlagRun=0
              			    TempFlag=0
              			    FlagTest="Retest"
              			    for RetestDataFile in RetestDataFiles:
                                        TempDataFileName=re.split(r"_",RetestDataFile)
                                        DeviceName=TempDataFileName[0]          
                                        SortType=TempDataFileName[3]
                                        #LotWaferId=TempDataFileName[4]
                                        (FlagConfig,Version,Patch,TestItemNum,DigitalTestItemNum,TestItemNames)=Config(DeviceName,SortType,ConfigPath,ConfigureFile)                  
                                        
                                        GaugeCount=GaugeCount+float(6)/len(WaferIDInData)
                                        self.GaugeInData.SetValue(GaugeCount)
                                        
                                        if string.upper(SortType)==string.upper("Sort0"):
                                            SortType="Sort2"
                                        (TempFlag,ProgramName,TesterName,Operator,ChannelMap)=NewUiData2BHTC(LotPath,RetestDataFile,TempFileBHTC,TestItemNum,TestItemNames,DigitalTestItemNum,FlagTest)  
                                        GaugeCount=GaugeCount+float(20)/len(WaferIDInData)
                                        self.GaugeInData.SetValue(GaugeCount)
                                        
                                        ###############################################
                                        #Zip the converted retest data file 
                                        ###############################################
                                        os.chdir(os.path.join(LotPath,FlagTest))
                                        if re.search("Sort1",SortType,re.I):
                                            ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_",SortType,"_",FlagTest,".zip"))
                                            self.MyZipFile(ZipFileName,RetestDataFile,True)
                                        if re.search("Sort2",SortType,re.I) or re.search("Sort0",SortType,re.I):
                                            ZipFileName="".join((Device,"_",Version,"_",os.path.basename(LotPath),"_","Sort2","_",FlagTest,".zip"))
                                            self.MyZipFile(ZipFileName,RetestDataFile,True)
                                        TempFlagRun=TempFlagRun or TempFlag
              			        GaugeCount=GaugeCount+float(10)/len(WaferIDInData)
                                        self.GaugeInData.SetValue(GaugeCount)
              			    if TempFlagRun:
                                        FlagRun=TempFlagRun
              			GaugeCount=GaugeCount+float(10)/len(WaferIDInData)
                                self.GaugeInData.SetValue(GaugeCount)
                                ###########################################
              			#Print out the related customer data
              			###########################################
              			if not FlagRun:                                    
                                    GaugeCount=GaugeCount+float(2)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                                    FlagRun=BHTC2CustData(LotPath,Device,TestItemNum,TesterName,ProgramName,Version,LotWaferId,Patch,SortType,Operator,ChannelMap,StarTime,BinDefinePath,TempFileBHTC,Title)
                                    PassWaferLogFH=open(os.path.join(LogPath,"passwafer.log"),"a")
                                    PassWaferLogFH.write("%26s%5s%15s%5s%20s%5s%18s%5s%12s%5s" %(TimeConvert,"|",Device,"|",LotNumInData,"|",LotWaferId,"|",SortType,"\n"))
                                    PassWaferLogFH.close()
 
                                    GaugeCount=GaugeCount+float(30)/len(WaferIDInData)
                                    self.GaugeInData.SetValue(GaugeCount)
                            else:
                                ErrorFH=open(ErrorLogFile,"a")
                                ErrorFH.write(TimeConvert),
                                ErrorFH.write("\tNot found device:"),
                                ErrorFH.write(Device),
                                ErrorFH.write("\'s configure data in file:"),
                                ErrorFH.write(ConfigureFile),
                                ErrorFH.write("! When Converting File:")
                                ErrorFH.write(WaferFile)
                                ErrorFH.write("\n")
                                ErrorFH.close()
                                dlg = wx.MessageDialog(self, r'The Device configue data can not be found in configruation file In Data!\n ',
                                        'A Error Box',
                                        wx.OK | wx.ICON_INFORMATION
                                        #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                                        )
                                dlg.ShowModal()
                                dlg.Destroy()
                                    #TempTime=time.asctime()
                                    #print TempTime
                        else:
                            Msg="".join(("Wafer:",str(WaferId)," SortType:",str(SortType),r'The First Test Data file can not be found in Data directory In Data! '))
                            dlg = wx.MessageDialog(self,Msg,'A Error Box',
                            					wx.OK | wx.ICON_INFORMATION
                            					#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                            					)
                            dlg.ShowModal()
                            dlg.Destroy()
                
            self.StartButtonInData.Enable()
            self.ReConfigButtonInData.Enable()
            self.ExitButtonInData.Enable()
            self.GaugeInData.SetValue(100)
					
    def OnReConfigButtonInDataButton(self, event):
        global WaferIDInData
        global SortTypesInData
        global LotNumInData
        global DeviceNameInData
		
        self.WaferNoTextCtrlInData.SetValue("01;")
        WaferIDInData="01;"
		
        self.SortTypeRadioBoxInData.SetSelection(0)
        SortTypesInData=["Sort1"]
		
        self.LotNoTextCtrlInData.SetValue("")        
        LotNumInData=""
		
        self.DeviceChoiceInData.SetSelection(-1)
        DeviceInData=""
        self.VersionChoiceInData.SetSelection(-1)
        VersionInData=""

    def OnExitButtonInDataButton(self, event):
        sys.exit()
    def OnTestDataPathTextCtrlInCofigrationText(self, event):
        global TestDataDir
        if event.GetString()=="":
            dlg = wx.MessageDialog(self, 'The TestDataDir must not be empty In configration!',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()   
        else:
            TestDataDir=event.GetString()
            
        #print TestDataDir

    def OnTestDataPathButtonInConfigrationButton(self, event):
        # In this case we include a "New directory" button. 
		dlg = wx.DirDialog(self, "Choose a directory:",
							style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

		# If the user selects OK, then we process the dialog's data.
		# This is done by getting the path data from the dialog - BEFORE
		# we destroy it. 
		if dlg.ShowModal() == wx.ID_OK:
			global TestDataDir            
			TestDataDir=dlg.GetPath()
			self.TestDataPathTextCtrlInCofigration.SetValue(TestDataDir)
                        
                        ConfigPath=os.path.join(ProjectPath,"Config")
                        os.chdir(ConfigPath)
			InitFile = open("InitSetting_Manual","r+")
			InitFileOut= open("InitSetting_ManualOut","w")
			Flag=1
			for Line in InitFile.readlines():
				if re.search(r'TestDataDir=',Line.re.I):
					InitFileOut.write("TestDataDir=%s\n" % TestDataDir)
					Flag=0
				else :
					InitFile.write(Line)
			if Flag:
				InitFileOut.write("TestDataDir=%s\n" % TestDataDir)
			InitFile.close
			InitFileOut.close
			del InitFile
			del InitFileOut
			os.remove("InitSetting_Manual")            
			os.renames("InitSetting_ManualOut","InitSetting_Manual")   
				
			#print LotNum 
			#print len(TempArray)

		# Only destroy a dialog after you're done with it.
		dlg.Destroy()


    def OnLotNoButtonInDataButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",
                            style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInData
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInData=os.path.basename(dlg.GetPath())
            self.LotNoTextCtrlInData.SetValue(LotNumInData)
            #print LotNumInData 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    def OnSortTypeRadioBoxInDataRadiobox(self, event):
        global SortTypesInData
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInData="Sort1"
        elif SortTypeSelect==1:
            SortTypesInData="Sort2"         
        	
        #print SortTypesInData  
    def ProcessShow(self,WaferNum):
        
        count=0
        for Index in range(100):
            time.sleep(float(8)/100*WaferNum)
            self.GaugeInData.SetValue(count)
            count = count + 1

    def OnDeviceChoiceInMapDataChoice(self, event):
        global DeviceInMapData
        global FlagDeviceInMap
        global FlagLotNumInMap
        #global FlagSortType       
        global FlagVersionInMap
        
        DeviceInMapData=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)

        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInMapData.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInMapData,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInMapData.Append(TempArray[Index])
                    
        #    elif re.search(r'Device=',Line,re.I):
        #        Line=Line.strip()
        #        TempArray=re.split(r'=|,',Line)
        #        DeviceInData.append(TempArray[1])
        #        VersionInData[TempArray[1]]=TempArray[3]
        #self.DeviceChoiceInData.SetValue(DeviceInData)        
        InitiFile.close      
        if DeviceInMapData=="":
            FlagDeviceInMap=False
        else:
            FlagDeviceInMap=True
        
        if FlagDeviceInMap and FlagVersionInMap and FlagLotNumInMap :
            self.StartButtonInMapData.Enable()
            self.ViewButtonInMapData.Enable()
        else:
            self.StartButtonInMapData.Disable()
            self.ViewButtonInMapData.Disable()
        #print DeviceInMapData,"FlagDeviceInMap:",FlagDeviceInMap


    def OnLotNoTextCtrlInMapDataText(self, event):
        global LotNumInMapData
        global FlagDeviceInMap
        global FlagLotNumInMap
        global FlagVersionInMap
        
        LotNumInMapData =event.GetString()
        if LotNumInMapData=="":
           FlagLotNumInMap=False
        else:
           FlagLotNumInMap=True
        
        if FlagDeviceInMap and FlagVersionInMap and FlagLotNumInMap :
            self.StartButtonInMapData.Enable()
            self.ViewButtonInMapData.Enable()
        else:
            self.StartButtonInMapData.Disable()
            self.ViewButtonInMapData.Disable()
        #print LotNumInMapData,"FlagLotNumInMap:",FlagLotNumInMap

    def OnLotNoButtonInMapDataButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",
                            style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInMapData
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInMapData=os.path.basename(dlg.GetPath())
            self.LotNoTextCtrlInMapData.SetValue(LotNumInMapData)
            #print LotNumInMapData 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()


    def OnSortTypeRadioBoxInMapDataRadiobox(self, event):
        global SortTypesInMapData
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInMapData=["Sort1"]
        elif SortTypeSelect==1:
            SortTypesInMapData=["Sort2"]
        elif SortTypeSelect==2:
            SortTypesInMapData=["Sort1","Sort2"]    
	
         
        	
        #print SortTypesInMapData 

    def OnStartButtonInMapDataButton(self, event):
        self.ViewButtonInMapData.Disable()
        self.StartButtonInMapData.Disable()
        self.ExitButtonInMapData.Disable()
        global DeviceInMapData 
        global SortTypesInMapData
        global LotNumInMapData
        global TestDataDir
        global VersionInMapData
        global TestDataDir
	
        #Device=DeviceInData	
        if DeviceInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        elif LotNumInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        try:
            os.chdir(TestDataDir)
	
        except OSError:
            msg="".join((r"The TestDataPath:\"",TestDataDir,"\"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        
        else:  
            self.RunConvertMapData(TestDataDir,DeviceInMapData,SortTypesInMapData,LotNumInMapData)
            self.StartButtonInMapData.Enable()
            self.ExitButtonInMapData.Enable()
            self.ViewButtonInMapData.Enable()
        

    def RunConvertMapData(self,TestDataDir,DeviceInMapData,SortTypesInMapData,LotNumInMapData): 
        DeviceVersion="".join((DeviceInMapData,"_",VersionInMapData))
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInMapData)
        MapDir=os.path.join(LotPath , "Map")
        ErrorMsg= "".join((r'The Direcotry: ',MapDir,r' is not exist InMapData!\n '))
        if not os.path.isdir(MapDir):                   
            dlg = wx.MessageDialog(self,ErrorMsg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        else :
            os.chdir(MapDir)
            files=glob.glob('*.map')
            
            FlagTempRun=False
            
            for SortType in SortTypesInMapData:
                #OutFileName=LotNumInMapData + "_" + SortType + "_" + "mapdata.txt"
                OutFileName="".join((LotNumInMapData , "_" ,SortType ,"_" ,"MapData.txt"))                
                
                OutFile=open(OutFileName,"w")
                TotalGoodDie=0
                for file in files:
                    PassDie=0                
                    if re.search(SortType,file,re.I):
                        FlagTempRun=True
                        MapFile=open(file)
                        Lines=MapFile.readlines()
                        for Line in Lines:
                            if re.search("\s+\d+\s+[\d+|\w+|\+]\s+\d+\s+\d+\.\d+%\s+PASS;",Line,re.I):
                                TempDatas=re.split("\s+",Line)
                                PassDie=int(TempDatas[3])                        
                                TotalGoodDie=TotalGoodDie+PassDie
                            
                        OutFile.write("%s : %d\n" % (file,PassDie))
                OutFile.write("Total Passed:  %d\n" % TotalGoodDie)
                OutFile.close
            if not FlagTempRun:
                ErrorMsg="".join(("Not find Device:",DeviceInMapData," ",SortType," Map File!"))
                dlg = wx.MessageDialog(self,ErrorMsg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
                dlg.ShowModal()
                dlg.Destroy()
                
                
    def OnViewButtonInMapDataButton(self, event):
    	   
        global DeviceInMapData 
        global SortTypesInMapData
        global LotNumInMapData
        global TestDataDir
        global VersionInMapData
        
        self.StartButtonInMapData.Disable()
        self.ExitButtonInMapData.Disable()
        self.ViewButtonInMapData.Disable()
        
	      
	      
        #Device=DeviceInData	
        if DeviceInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        elif LotNumInMapData=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        else:  
            DeviceVersion="".join((DeviceInMapData,"_",VersionInMapData))
            LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInMapData)
            MapDir=os.path.join(LotPath , "Map")
            ErrorMsg= "".join((r'The Direcotry: ',MapDir,r' is not exist InMapData!\n '))
            if not os.path.isdir(MapDir):                   
                dlg = wx.MessageDialog(self,ErrorMsg ,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
                dlg.ShowModal()
                dlg.Destroy()
            else :
                os.chdir(MapDir)            
                for SortType in SortTypesInMapData:
                    #OutFileName=LotNumInMapData + "_" + SortType + "_" + "mapdata.txt"
                    MapDataFileName="".join((LotNumInMapData , "_" ,SortType ,"_" ,"MapData.txt"))
                    if os.path.isfile(MapDataFileName):
                        MapDataFileNameFH=open(MapDataFileName,"r")
                        msg=""
                        for Line in MapDataFileNameFH.readlines():
                            msg="".join((msg,Line))
                        MapDataFileNameFH.close()
                        dlg = wx.lib.dialogs.ScrolledMessageDialog(self, msg, "message test")
                        dlg.ShowModal()
                    else:
                        ErrorMsg= "".join((DeviceInMapData," ",SortType,r' MapData is not exist!\n You can convert it at first!\n '))
                        dlg = wx.MessageDialog(self,ErrorMsg,'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
                        dlg.ShowModal()
                        dlg.Destroy()
        self.StartButtonInMapData.Enable()
        self.ExitButtonInMapData.Enable()
        self.ViewButtonInMapData.Enable()
    def OnExitButtonInMapDataButton(self, event):
        sys.exit()

    def OnVersionChoiceInMapDataChoice(self, event):
        global VersionInMapData
        global FlagDeviceInMap
        global FlagLotNumInMap
        global FlagVersionInMap
        
        VersionInMapData=event.GetString()
        if VersionInMapData=="":
            FlagVersionInMap=False
        else:
            FlagVersionInMap=True
        
        if FlagDeviceInMap and FlagVersionInMap and FlagLotNumInMap :
            self.StartButtonInMapData.Enable()
        else:
            self.StartButtonInMapData.Disable()    
        #print VersionInMapData,"FlagVersionInMap:",FlagVersionInMap
    
    def MyZipFile(self,ZipFileName,FileName,FlagDelFile):
        if not os.path.isfile(ZipFileName):
            FileNameFH=zipfile.ZipFile(ZipFileName,"w")
            FileNameFH.write(FileName,None,zipfile.ZIP_DEFLATED)
            FileNameFH.close()
            
        else:
            FlagFileExist=False
            FileNameFH=zipfile.ZipFile(ZipFileName,"r")
            for TempFileName in FileNameFH.namelist():
              	if re.search(FileName,TempFileName,re.I):
                    FlagFileExist=True
                    break
            FileNameFH.close()
            if not FlagFileExist:    
              	FileNameFH=zipfile.ZipFile(ZipFileName,"a")
              	FileNameFH.write(FileName,None,zipfile.ZIP_DEFLATED)
              	FileNameFH.close()
        if FlagDelFile:
            os.unlink(FileName)

    def OnDeviceChoiceInWaferMapChoice(self, event):
        global DeviceInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType       
        global FlagVersionInWaferMap
        global FlagWaferIdInWaferMap
        
        DeviceInWaferMap=event.GetString()
        ConfigPath=os.path.join(ProjectPath,"Config")
        os.chdir(ConfigPath)

        InitiFile=open("InitSetting_Manual","r")
        self.VersionChoiceInWaferMap.Clear()
        for Line in InitiFile.readlines():
            if re.search(DeviceInWaferMap,Line,re.I):
                Line=Line.strip()
                TempArray=re.split(r'=|,',Line)
                #TestDataDir=TempArray[1] 
                for Index in range(3,len(TempArray)):
                    self.VersionChoiceInWaferMap.Append(TempArray[Index])
                    
        #    elif re.search(r'Device=',Line,re.I):
        #        Line=Line.strip()
        #        TempArray=re.split(r'=|,',Line)
        #        DeviceInData.append(TempArray[1])
        #        VersionInData[TempArray[1]]=TempArray[3]
        #self.DeviceChoiceInData.SetValue(DeviceInData)        
        InitiFile.close      
        if DeviceInWaferMap=="":
            FlagDeviceInWaferMap=False
        else:
            FlagDeviceInWaferMap=True
        
        if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap and FlagWaferIdInWaferMap :
            self.StartButtonInWaferMap.Enable()
            
        else:
            self.StartButtonInWaferMap.Disable()
            self.NextButtonInWaferMap.Disable()
            self.PreButtonInWaferMap.Disable()
        print DeviceInWaferMap,"FlagDeviceInMap:",FlagDeviceInWaferMap



    def OnVersionChoiceInWaferMapChoice(self, event):
        global VersionInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType
        global FlagWaferIdInWaferMap
        global FlagVersionInWaferMap
        
        VersionInWaferMap=event.GetString()
        if VersionInWaferMap=="":
            FlagVersionInWaferMap=False
        else:
            FlagVersionInWaferMap=True
        
        if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap  and FlagWaferIdInWaferMap:
            self.StartButtonInWaferMap.Enable()
            
        else:
            self.StartButtonInWaferMap.Disable()
            self.StartButtonInWaferMap.Disable()
            self.NextButtonInWaferMap.Disable()
            self.PreButtonInWaferMap.Disable()
        print VersionInWaferMap,"FlagVersionInWaferMap:",FlagVersionInWaferMap

    def OnLotNumTextCtrlInWaferMapText(self, event):
        global LotNumInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType
        global FlagWaferIdInWaferMap
        global FlagVersionInWaferMap
        
        LotNumInWaferMap =event.GetString()
        if LotNumInWaferMap=="":
           FlagLotNumInWaferMap=False
        else:
           FlagLotNumInWaferMap=True
        
        if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap  and FlagWaferIdInWaferMap:
            self.StartButtonInWaferMap.Enable()
            
        else:
            self.StartButtonInWaferMap.Disable()
            self.StartButtonInWaferMap.Disable()
            self.NextButtonInWaferMap.Disable()
            self.PreButtonInWaferMap.Disable()
        print LotNumInWaferMap,"FlagLotNumInWaferMap:",FlagLotNumInWaferMap

    def OnWaferNoTextCtrlInWaferMapText(self, event):
        global WaferIdInWaferMap
        global FlagDeviceInWaferMap
        global FlagLotNumInWaferMap
        #global FlagSortType
        global FlagWaferIdInWaferMap
        global FlagVersionInWaferMap
        
        WaferIDInWaferMap=""
        TempData=event.GetString()
        if TempData == "":
            dlg = wx.MessageDialog(self, 'The WaferID must not be empty In MapData!\n The format is 01;02;...',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
			
        TempArray=re.split(r";",TempData)
        TempFlag=0
        for Temp in TempArray:
            if re.search("\D+",Temp,re.I):
                TempFlag=1
                continue
            elif len(Temp)>0:
				if int(Temp)>25:
					TempFlag=2
            else:
                TempArray.remove(Temp)        
				
		if TempFlag==1:
			dlg = wx.MessageDialog(self, 'There is some no digital in WaferID string In Data! ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
			dlg.ShowModal()
			dlg.Destroy()
		elif TempFlag==2:
			dlg = wx.MessageDialog(self, 'There is some wrong waferID(That is more than 25 In Data!',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
			dlg.ShowModal()
			dlg.Destroy() 
			
		WaferIdInWaferMap=TempArray
		if len(WaferIdInWaferMap)<1:
                    FlagWaferIdInWaferMap=False
                else:
                    FlagWaferIdInWaferMap=True
                if FlagDeviceInWaferMap and FlagVersionInWaferMap and FlagLotNumInWaferMap  and FlagWaferIdInWaferMap:
                    self.StartButtonInWaferMap.Enable()
                    
                else:
                    self.StartButtonInWaferMap.Disable()
                    self.NextButtonInWaferMap.Disable()
                    self.PreButtonInWaferMap.Disable()
            print WaferIdInWaferMap,"FlagWaferIdInWaferMap:",FlagWaferIdInWaferMap

    def OnLotNoButtonInWaferMapButton(self, event):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(self, "Choose a directory:",
                            style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            global LotNumInData
            #TempArray=re.split(r"\\",dlg.GetPath())
            #LotNumInData=TempArray[len(TempArray)-1]
            LotNumInData=os.path.basename(dlg.GetPath())
            self.LotNumTextCtrlInWaferMap.SetValue(LotNumInData)
            #print LotNumInData 
            #print len(TempArray)

        # Only destroy a dialog after you're done with it.
        dlg.Destroy()

    
    def OnSortTypeRadioBoxInWaferMapRadiobox(self, event):
        global SortTypesInWaferMap
        SortTypeSelect=event.GetInt()
        if SortTypeSelect==0:
            SortTypesInWaferMap="Sort1"
        elif SortTypeSelect==1:
            SortTypesInWaferMap="Sort2"  
        #print SortTypesInWaferMap
    def OnStartButtonInWaferMapButton(self, event):
        self.StartButtonInWaferMap.Disable()
        
        global DeviceInWaferMap
        global SortTypesInWaferMap
        global LotNumInWaferMap
        global WaferIdInWaferMap
        global TestDataDir
        global VersionInWaferMap
        global TestDataDir
        global IndexInWaferMap
	
        #Device=DeviceInData	
        if DeviceInWaferMap=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The DeviceNmae must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        if WaferIdInWaferMap=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The WaferId must not be empty In Data!\n Maybe the format is not right!the right format is 01;02;... ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        elif LotNumInWaferMap=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The LotNum must not be empty In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        elif TestDataDir=="":
            #TempData=event.GetString()        
            dlg = wx.MessageDialog(self, r'The TestData Path is not confige In Data!\n ',
								'A Error Box',
								wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        try:
            os.chdir(TestDataDir)
	
        except OSError:
            msg="".join((r"The TestDataPath:\"",TestDataDir,"\"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))    
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
        try:
            os.chdir(LotPath)
	
        except OSError:
            msg="".join((r"The Lot directory:",LotPath,"isn't exist!When Using Manual Convert Data Tool."))
            dlg = wx.MessageDialog(self, msg,'A Error Box',wx.OK | wx.ICON_INFORMATION
								#wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
								)
            dlg.ShowModal()
            dlg.Destroy()
        
        else:
            DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))
            LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
            if len(WaferIdInWaferMap)>1:
                self.NextButtonInWaferMap.Enable()
                self.PreButtonInWaferMap.Enable()
            WaferMapFrame=MyWaferMapFrame(None,u"WaferMap Display",LotPath,WaferIdInWaferMap[0],SortTypesInWaferMap)
            WaferMapFrame.Show(True)
            self.StartButtonInWaferMap.Enable()
            IndexInWaferMap=0
        

    def OnNextButtonInWaferMapButton(self, event):
        global IndexInWaferMap
        global WaferIdInWaferMap
        global DeviceInWaferMap
        global SortTypesInWaferMap
        global LotNumInWaferMap
        global WaferIdInWaferMap
        global TestDataDir
        global VersionInWaferMap
        global TestDataDir
        DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
        IndexInWaferMap=IndexInWaferMap+1
        if IndexInWaferMap>1:
            self.PreButtonInWaferMap.Enable()
        if IndexInWaferMap==len(WaferIdInWaferMap)-1:
            self.NextButtonInWaferMap.Disable()    
        if 0<IndexInWaferMap<len(WaferIdInWaferMap):
            WaferMapFrame=MyWaferMapFrame(None,u"WaferMap Display",LotPath,WaferIdInWaferMap[IndexInWaferMap],SortTypesInWaferMap)
            WaferMapFrame.Show(True)
            self.StartButtonInWaferMap.Enable()
        

    def OnPreButtonInWaferMapButton(self, event):
        global IndexInWaferMap
        global WaferIdInWaferMap
        global DeviceInWaferMap
        global SortTypesInWaferMap
        global LotNumInWaferMap
        global WaferIdInWaferMap
        global TestDataDir
        global VersionInWaferMap
        global TestDataDir
        DeviceVersion="".join((DeviceInWaferMap,"_",VersionInWaferMap))
        LotPath=os.path.join(TestDataDir,DeviceVersion,LotNumInWaferMap)
        IndexInWaferMap=IndexInWaferMap-1
        if IndexInWaferMap==0:
            self.PreButtonInWaferMap.Disable()    
        if len(WaferIdInWaferMap)>IndexInWaferMap>=0:
            WaferMapFrame=MyWaferMapFrame(None,u"WaferMap Display",LotPath,WaferIdInWaferMap[IndexInWaferMap],SortTypesInWaferMap)
            WaferMapFrame.Show(True)
            self.StartButtonInWaferMap.Enable()

    def OnExitButtonInWaferMapButton(self, event):
        sys.exit()
        

    

    
        
